<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<script type="text/javascript" charset="UTF-8" src="/genJS/yaodian_zipCodCode.js"></script>

	<script type="text/javascript" charset="UTF-8" src="<c-rt:url value="/js/jquery.cascade.ext.js"/>"></script>
	<script type="text/javascript" charset="UTF-8" src="<c-rt:url value="/js/jquery.cascade.js"/>"></script>
	<script type="text/javascript" charset="UTF-8" src="<c-rt:url value="/js/jquery.templating.js"/>"></script>
${pu:reqSet('so', pu:get('com.yaodian100.ec.order.entity.ServiceOrders', param.serviceId)) }
${pu:listAdd('sopsParams', param.serviceId) }
${pu:reqSet('sops', pu:queryByHql('from ServiceOrderProduct where serviceId=?', pu:arrayGet('sopsParams'), null)) }
<style>
.tableAlignLeft td{
	text-align:left;
}
</style>
<h1>
退货转换货单(单号：${so.serviceId })
</h1>
<script>
function changeAddress(tagId, index){
	$("#"+tagId).attr("selectedIndex",index+1);
}
$(function(){

	function commonTemplate(item) {
		return "<option value='" + item.Value + "'>" + item.Text + "</option>"; 
	};
	function commonMatch(selectedValue) {
		return this.When == selectedValue; 
	};
	$.each(provinceArray,function(index, item){
        $("#province").append("<option value='" + item.Value + "'>" + item.Text + "</option>");
	  });
		$("#city").cascade("#province",{					
			list : cityArray,				
			template: commonTemplate,
			match: commonMatch 
		});
		$("#district").cascade("#city",{					
			list: districtArray,
			template: commonTemplate,
			match: commonMatch 
		});
	$.each(provinceArray,function(index, item){
			if ( item.Value == "${so.receiverProvince}" ){
				setTimeout("changeAddress(\"province\","+index+")", 500);
				//$("#province").attr("selectedIndex",index+1);
			}
		});
		
		$.each(cityArray,function(index, item){
			if ( item.When == "${so.receiverProvince}" ){
				$("#city").append("<option value='" + item.Value + "'>" + item.Text + "</option>");
			}
		});
		
		var newCityArray = $.grep(cityArray, function (item) { return item.When == "${so.receiverProvince}"; });
		$.each(newCityArray,function(index, item){
			if ( item.Value == "${so.receiverCity}" ){
				//$("#city").attr("selectedIndex",index+1);
				setTimeout("changeAddress(\"city\","+index+")", 500);
			}
		});
		
		$.each(districtArray,function(index, item){
			if ( item.When == "${so.receiverCity}" ){
				$("#district").append("<option value='" + item.Value + "'>" + item.Text + "</option>");
			}
		});
		
		newDistrictArray = $.grep(districtArray, function (item) { return item.When == "${so.receiverCity}"; });
		$.each(newDistrictArray,function(index, item){
			if ( item.Value == "${so.receiverArea}" ){
				//$("#district").attr("selectedIndex",index+1);
				setTimeout("changeAddress(\"district\","+index+")", 500);
			}
		});

$('.productQty').each(function(){
			
			$(this).change(function(){
				id=$(this).attr('id');
				index=id.replace('qty','');
				qty=$(this).attr('value');
				$('.prodSpecId'+index).each(function(){
					$(this).attr('disabled', 'disabled');
					$(this).css('display', 'none');
				});
				$('.prodSpecId'+index).each(function(i){
					if(i<qty){
						$(this).css('display', '');
						$(this).attr('disabled', '');
					}
				});
			});
		});
		$('.prodSpecId').each(function(){
			$(this).attr('disabled', 'disabled');
			$(this).css('display', 'none');
		});
});
function checkForm(){
	var returnCount=0;
	$('.qtys0').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys1').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys2').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys3').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys4').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys5').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys6').each(function(){
		returnCount+=$(this).attr('value');
	});
	$('.qtys7').each(function(){
		returnCount+=$(this).attr('value');
	});
	
	var errorMessage="";
	var error=0;	
	if(returnCount==0){
		errorMessage+='请选择换货商品数数量\r\n';
	}
	$('.prodSpecId').each(function(i){
		if($(this).attr('disabled')!=true){
			if($(this).attr('value')==''){
				error++;
			}
		}
	});
	if(error>0){
		errorMessage+='请选择换货商品属性\r\n';
	}

	error=0;
	$('.reason').each(function(){
		if($(this).attr('value')==''){
			error++;
		}
	});
	if(error>0){
		errorMessage+="请选择换货原因\r\n";
	}
	error=0;
	
	$('.description').each(function(){
		if($(this).attr('value')==''){
			error++;
		}
	});
	if(error>0){
		errorMessage+="请填写换货原因描述\r\n";
	}
	error=0;

	$('.accessaryDescription').each(function(){
		if($(this).attr('value')==''){
			error++;
		}
	});
	if(error>0){
		errorMessage+="请填写配件赠品状态\r\n";
	}
	if($('#receiverName').attr('value')==''){
		errorMessage+="请填联络人姓名\r\n";
	}
	if($('#province').attr('value')==''
		|| $('#city').attr('value')==''
		|| $('#district').attr('value')==''
		|| $('#receiverAddr').attr('value')==''
		|| $('#receiverZip').attr('value')==''){
		errorMessage+="请填联络地址\r\n";
	}

	if($('#receiverMobile').attr('value')==''){
		if($('#receiverPhoneArea').attr('value')==''
			|| $('#receiverPhone').attr('value')==''
			){
			
			errorMessage+="请填手机电话或固定电话\r\n";
		}else{
			if(
					$('#receiverPhone').attr('value').length<5
					|| $('#receiverPhone').attr('value').length>10
					|| isNaN($('#receiverPhone').attr('value'))
				){
				
				errorMessage+="固定电话为长度5～10的数字\r\n";
			}
		}
		
	}else if(isNaN($('#receiverMobile').attr('value')) || $('#receiverMobile').attr('value').length>11){
		errorMessage+="手机电话为长度小于11的数字\r\n";
	}
	

	if(errorMessage!=''){
		alert(errorMessage);
	}
	else{
		document.returnForm.submit();
	}
}
</script>
<form name="returnForm" method="post" action="/ecadmin/serviceOrder/returnToChange.do">
<input type="hidden" name="serviceId" value="${param.serviceId }"/>
<input type="hidden" name="paymentTp" value="${so.paymentTp }"/>
<input type="hidden" name="orderId" value="${so.orderId }"/>
<input type="hidden" name="memberId" value="${so.memberId }"/>
<input type="hidden" name="orderProdId" value="${sops[0].orderProdId }"/>
<table class="tb-1 tableAlignLeft">
<thead>
<tr>
	<th>orderProdId</th><th>明细</th>
</tr>
</thead>
<tbody>
	
		
		
		<c-rt:forEach items="${sops }" var="sop">
		<tr>
			<td>${sop.orderProdId }<input type="hidden" name="orderProdId" value="${sop.orderProdId }"/></td>
			
			<td>
			<table>
			<c-rt:forEach items="${sop.serviceOrderDetail}" var="sod" varStatus="status">
			<tr><td>
			<table><tr><td>
			<c-rt:if test="${sod.detailTp=='0'}">
			<c-rt:set var="detailTp" scope="request" value="0"/>
				<span class="type-0">主商品</span>
				</c-rt:if>
				<c-rt:if test="${sod.detailTp=='1'}">
				<c-rt:set var="detailTp" scope="request" value="1"/>
				<span class="type-1">预购</span>
				</c-rt:if>
				<c-rt:if test="${sod.detailTp=='2'}">
				<c-rt:set var="detailTp" scope="request" value="2"/>
				<span class="type-2">赠品</span>
				</c-rt:if>
				<c-rt:if test="${sod.detailTp=='3'}">
				<c-rt:set var="detailTp" scope="request" value="3"/>
				<span class="type-3">加购</span>
				</c-rt:if>
				<c-rt:if test="${sod.detailTp=='4'}">
				<c-rt:set var="detailTp" scope="request" value="4"/>
				<span class="type-4">活动</span>
				</c-rt:if>
				<c-rt:if test="${sod.detailTp=='5'}">
				<c-rt:set var="detailTp" scope="request" value="5"/>
				<span class="type-5">满额购</span>
				</c-rt:if>
				<c-rt:if test="${sod.detailTp=='6'}">
				<c-rt:set var="detailTp" scope="request" value="6"/>
				<span class="type-6">任选</span>
				</c-rt:if>
				<c-rt:if test="${sod.detailTp=='7'}">
				<c-rt:set var="detailTp" scope="request" value="7"/>
				<span class="type-7">精品</span>
				</c-rt:if>
				${sod.prodName }[${sod.prodSpecName }]x
				<select name="qtys" id="qty${status.index }" class="qtys${detailTp } productQty">
				<c-rt:forEach begin="0" end="${sod.qty}" varStatus="index">
				<option value="${index.index }">${index.index }</option>
				</c-rt:forEach>
				</select>
				</td>
				<td>
				${pu:reqSet('paramsProdSpecs', null) }
					${pu:reqSet('parasProdSpecs', null)}
					${pu:listAdd('paramsProdSpecs', sod.prodId)}
					${pu:listAdd('paramsProdSpecs', 'Y')}
					
					${pu:reqSet('hqlProdSpecs', 'from Specification where productId=? and isDelete!=?')}
					${pu:reqSet('prodSpecs', pu:queryByHql(hqlProdSpecs, pu:arrayGet('paramsProdSpecs'), null))}
					
				  <c-rt:forEach begin="1" end="${sod.qty}" step="1" varStatus="qtyI">
				 
	              <select name="prodSpecIds" class="prodSpecId prodSpecId${status.index }" disabled="disabled">
					<option value="">请选择</option>
					<c-rt:forEach items="${prodSpecs}" var="spec">
						<option value="${sod.orderDetailId}_1_${spec.specificationId }"
							<c-rt:if test="${spec.specificationId == sod.prodSpecId}">selected="selected"</c-rt:if>>${spec.specificationName}</option>
					</c-rt:forEach>
				</select> 
				
				</c-rt:forEach>
				
				</td></tr></table>
				</td></tr>
			</c-rt:forEach>
			</table>
			
			</td>
			
		</tr>
		</c-rt:forEach>
		
</tbody>
</table>

<table class="tb-1 tableAlignLeft">
	<tr>
		<th>
		换货原因
		</th>
		<td>
		 <select name="reason" class="reason">
	          <option value="">请选择原因</option>
	          <option value="订购错误">订购错误</option>
	          <option value="商品发错">商品发错</option>
	          <option value="商品或外包装破损">商品或外包装破损</option>
	          <option value="商品不如预期">商品不如预期</option>
	          <option value="商品属性不符">商品属性不符</option>
	          <option value="价格比较贵">价格比较贵</option>
	          <option value="与介绍不符">与介绍不符</option>
	          <option value="改买其他款式">改买其他款式</option>
	          <option value="商品未如期收到">商品未如期收到</option>
	          <option value="不会使用">不会使用</option>
	          <option value="其他">其他</option>
	          </select>
		</td>
	</tr>
	<tr>
		<th>
		换货原因描述
		</th>
		<td>
		<textarea name="description" class="description" rows="5" cols="100"></textarea>
		</td>
	</tr>
	<tr>
		<th>
		配件赠品状态
		</th>
		<td>
		<input class="return-txtfild accessaryDescription" type="text" name="accessaryDescription" value="" size="100"/>
		</td>
	</tr>
	<tr>
		<th>
		姓名
		</th>
		<td>
		<input type="text" name="receiverName" id="receiverName" value="${so.receiverName }" size="10" />
		</td>
	</tr>
	<tr>
		<th>联络地址</th>
		<td>
		<select id="province" name="receiverProvince" class="c-prov"><option value="">== 选择省 ==</option></select> 
              市：<select name="receiverCity" id="city"> 
                <option value="">== 选择城市 ==</option>
              </select> 
              区：<select name="receiverArea" id="district"> 
                <option value="">== 选择地区 ==</option>
              </select> 
              <br /> 
              邮编：<input type="text" name="receiverZip" id="receiverZip" value="${so.receiverZip}"/>
              街道：<input size="50" name="receiverAddr" id="receiverAddr" value="${so.receiverAddr }" /> 
		</td>
	</tr>
	<tr>
		<th>手机电话</th>
		<td><input type="text" name="receiverMobile" id="receiverMobile" value="${so.receiverMobile }" size="10" /></td>
	</tr>
	<tr>
		<th>固定电话</th>
		<td>
			<input type="text" name="receiverPhoneArea" id="receiverPhoneArea" value="${so.receiverPhoneArea }" size="3" />-<input type="text" name="receiverPhone" id="receiverPhone" value="${so.receiverPhone }" size="7" />-分机<input type="text" name="receiverExt" id="receiverExt" value="${so.receiverExt }" size="4" />
		</td>
	</tr>
	<tr>
		<th></th>
		<td>
		<input type="button" value="送出" onclick="checkForm()"/>
		<input type="reset" value="重置"/>
		</td>
	</tr>
</table>
</form>